<template>
  <!-- 选择辅助检查模板 -->
  <el-drawer title="辅助检查模板" size="600px" :visible="value" custom-class="drawer-box" :wrapperClosable="false" :destroy-on-close="true" @open="onOpen" @close="onClose" :append-to-body="true">
    <!-- <div class="p-sm" style="padding-bottom:0;">
      <el-form :inline="true" @submit.native.prevent="getTemplate(-1)">
        <el-form-item>
          <el-input v-model="form.name" placeholder="模板名称"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" circle icon="el-icon-search" native-type="submit"> </el-button>
        </el-form-item>
      </el-form>
    </div> -->
    <table class="table-box">
      <thead>
        <tr>
          <th>模板名称</th>
          <th>项目</th>
        </tr>
      </thead>
      <tbody>
        <tr v-for="(item,index) in tableList" :key="index" @click="onClickItem(item)">
          <td style="white-space:nowrap ;">{{item.template.name}}</td>
          <td>
            <span v-for="(item,index) in item.baseTemplateAdviceBeans" :key="index">{{index>0?"，":''}}{{item.adviceDesc}} （<span v-for="(item,index) in toArrayDisplay(item.display)">{{index>0?"，":''}}{{item|changeAssist(checkPartArr)}}</span>）</span>
          </td>
        </tr>
      </tbody>
    </table>
    <div v-if="tableList.length == 0" style="color:#999;padding:10px 0;text-align:center;">
      <i class="iconfont iconwushuju" style="font-size:40px;"></i>
      <div>暂无数据</div>
    </div>
    <br>
    <pager v-model="pager" @change-pagenum="getTemplate"></pager>
  </el-drawer>
</template>
<script>
export default {
  props: ["value"],
  components: {
  },
  data() {
    return {
      tableList: [],
      pager: { pageSize: 20, pageNum: 1, total: 0 },
      checkPartArr: []
    };
  },
  mounted() {
    let th = this;
    th.getCommonConfigByKey("检查部位").then(res => {
      th.checkPartArr = res;
    });
  },
  methods: {
    onClickItem(obj) {
      let th = this;
      if (
        !obj.baseTemplateAdviceBeans ||
        obj.baseTemplateAdviceBeans.length == 0
      ) {
        return;
      }
      th.$emit("change", obj);
      th.onClose();
    },
    toArrayDisplay(arr) {
      let th = this;
      let obj = [];
      if (!arr) return obj;
      if (typeof arr == "string") {
        obj = JSON.parse(arr);
      }
      return obj;
    },
    getTemplate(type) {
      let th = this;
      if (type == -1) {
        th.pager.pageNum = 1;
        th.pager.total = 0;
      }
      let j = {status:1};
      Object.assign(j, th.pager);
      th.tableList = [];
      th.$api.assistInspectionTemplatePageQuery(j).then(res => {
        if (res.executed) {
          if (res.dataBody.list) {
            th.tableList = res.dataBody.list;
            th.pager.total = res.dataBody.total;
          }
        }
      });
    },
    onOpen() {
      let th = this;
      th.$nextTick(function() {
        th.getTemplate(-1);
      });
    },
    onClose() {
      let th = this;
      th.$emit("input", false);
    }
  }
};
</script>
